using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Gadgets.Setups
{
    public partial class eParameters : WeifenLuo.WinFormsUI.Docking.DockContent  
    {
        public eParameters()
        {
            InitializeComponent();
        }

        private void eParameters_Load(object sender, EventArgs e)
        {
            try
            {
                ABSCommonLibrary.CreateGridView(ref gridControl1);
                colITEM_VALUE.FormatSpecifier = DeclareLibrary.NUMBER_FORMAT;
            }
            catch (Exception ex)
            {
                ABSCommonLibrary.ShowErrorMessage(ex.ToString());
            }
        }

        private void LoadGrid()
        {
            DataSet v_data = ABSCommonLibrary.DoInquiry(
                CommonLibrary.CommonLibrary.BOSC013002, new object[0] { });
            gridControl1.SetDataBinding(v_data, v_data.Tables[0].TableName);
        }
        private void eParameters_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.F11)
                {
                    if (((DataSet)gridControl1.DataSource).Tables[0].GetChanges() != null)
                    {
                        foreach (DataRow row in ((DataSet)gridControl1.DataSource).Tables[0].GetChanges().Rows)
                        {
                            if (row.RowState == DataRowState.Modified)
                            {
                                object[] p_param = new object[9];
                                p_param[0] = row["ITEM_CODE"];
                                p_param[1] = row["ITEM_VALUE"];
                                p_param[2] = row["DESCRIPTION"];
                                int error_code = Convert.ToInt32(ABSCommonLibrary.DoExecute(
                                    CommonLibrary.CommonLibrary.BOSC009002, ref p_param));
                            }
                        }
                        LoadGrid();
                    }
                }
                else if (e.KeyCode == Keys.F9)
                {
                    LoadGrid();
                }
            }
            catch (Exception ex)
            {
                ABSCommonLibrary.ShowErrorMessage(ex.ToString());
            }
        }
    }
}